package com.jz.community.moduleshopping.orderDetail.ui;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.support.v4.widget.NestedScrollView;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.jz.community.basecomm.base.BaseHtml5Activity;
import com.jz.community.basecomm.base.BaseMvpActivity;
import com.jz.community.basecomm.base.BaseX5WebActivity;
import com.jz.community.basecomm.bean.BaseResponseInfo;
import com.jz.community.basecomm.constant.AppConstants;
import com.jz.community.basecomm.constant.Constant;
import com.jz.community.basecomm.constant.ConstantErrorCode;
import com.jz.community.basecomm.mvp.BaseMvpPresenter;
import com.jz.community.basecomm.routerUtils.RouterCommonUtils;
import com.jz.community.basecomm.routerUtils.RouterIntentConstant;
import com.jz.community.basecomm.task.ITaskCallbackListener;
import com.jz.community.basecomm.utils.BaseImageLoaderUtils;
import com.jz.community.basecomm.utils.CharacterUtils;
import com.jz.community.basecomm.utils.ConverterUtils;
import com.jz.community.basecomm.utils.DialogUtils;
import com.jz.community.basecomm.utils.LoggerUtils;
import com.jz.community.basecomm.utils.Preconditions;
import com.jz.community.basecomm.utils.SHelper;
import com.jz.community.basecomm.utils.WpToast;
import com.jz.community.basecomm.utils.rxbus.RxBus;
import com.jz.community.moduleshopping.R;
import com.jz.community.moduleshopping.R2;
import com.jz.community.moduleshopping.confirmOrder.bean.SubmitOrderResultBean;
import com.jz.community.moduleshopping.confirmOrder.enums.OrderPayFormType;
import com.jz.community.moduleshopping.confirmOrder.payPop.NewCommPayPopUp;
import com.jz.community.moduleshopping.orderDetail.adapter.OrderDetailAdapter;
import com.jz.community.moduleshopping.orderDetail.bean.OrderDetailBean;
import com.jz.community.moduleshopping.orderDetail.bean.OrderEvent;
import com.jz.community.moduleshopping.orderDetail.task.OrderDeleteTask;
import com.jz.community.moduleshopping.orderDetail.task.OrderDetailTask;
import com.jz.community.moduleshopping.orderList.bean.SpecialCouponBean;
import com.jz.community.moduleshopping.orderList.enums.OrderRefundMarkType;
import com.jz.community.moduleshopping.orderList.enums.OrderStatusType;
import com.jz.community.moduleshopping.orderList.task.ConfirmCancelOrderStatusTask;
import com.jz.community.moduleshopping.orderList.task.ConfirmOrderStatusTask;
import com.jz.community.moduleshopping.orderList.task.SpecialCouponForOrderTask;
import com.jz.community.moduleshopping.orderList.view.NotSnatchDialog;
import com.jz.community.moduleshopping.orderList.view.ReasonDialog;
import com.jz.community.moduleshopping.orderList.view.ReceivingGoodsDialog;
import com.jz.community.moduleshopping.orderList.view.SpecialCouponDialog;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;

import java.util.ArrayList;
import java.util.concurrent.TimeUnit;

import butterknife.BindView;
import cn.iwgang.countdownview.CountdownView;
import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

/**
 * Created by Target on 2018/4/6.
 * <p>
 * 订单详情
 */
@Route(path = RouterIntentConstant.MODULE_SHOPPING_ORDER_DETAIL)
public class OrderDetailActivity extends BaseMvpActivity implements OnRefreshListener {
    @BindView(R2.id.tv_back)
    ImageView tvBack;
    @BindView(R2.id.tv_title)
    TextView tvTitle;
    @BindView(R2.id.commit_order_toolbar)
    Toolbar commitOrderToolbar;
    @BindView(R2.id.iv_order_state)
    ImageView ivOrderState;
    @BindView(R2.id.view_line_one)
    TextView viewLineOne;
    @BindView(R2.id.tv_consignee_name)
    TextView tvConsigneeName;
    @BindView(R2.id.tv_consignee_phone)
    TextView tvConsigneePhone;
    @BindView(R2.id.iv_address_type)
    ImageView ivAddressType;
    @BindView(R2.id.tv_recommend_post)
    TextView tvRecommendPost;
    @BindView(R2.id.tv_consignee_address)
    TextView tvConsigneeAddress;
    @BindView(R2.id.tv_is_pick_ip_address)
    TextView tvIsPickIpAddress;
    @BindView(R2.id.iv_arrow_to_address_list)
    ImageView ivArrowToAddressList;
    @BindView(R2.id.ll_add_address)
    LinearLayout llAddAddress;
    @BindView(R2.id.view_line_two)
    TextView viewLineTwo;
    @BindView(R2.id.tv_delivery_method)
    TextView tvDeliveryMethod;
    @BindView(R2.id.tv_pay_type)
    TextView tvPayType;
    @BindView(R2.id.ll_pay_type)
    LinearLayout llPayType;
    @BindView(R2.id.tv_bottom_pay_type_line)
    TextView tvBottomPayTypeLine;
    @BindView(R2.id.tv_send_price)
    TextView tvSendPrice;
    @BindView(R2.id.ll_send_price_dialog)
    LinearLayout llSendPriceDialog;
    @BindView(R2.id.tv_goods_price)
    TextView tvGoodsPrice;
    @BindView(R2.id.tv_coupon_price)
    TextView tvCouponPrice;
    @BindView(R2.id.ll_coupon_dialog)
    LinearLayout llCouponDialog;
    @BindView(R2.id.tv_red_package_price)
    TextView tvRedPackagePrice;
    @BindView(R2.id.ll_user_red_package)
    LinearLayout llUserRedPackage;
    @BindView(R2.id.tv_red_package_line)
    TextView tvRedPackageLine;
    @BindView(R2.id.tv_share_reduce_money)
    TextView tvShareReduceMoney;
    @BindView(R2.id.ll_share_reduce)
    LinearLayout llShareReduce;
    @BindView(R2.id.share_reduce_line)
    TextView shareReduceLine;
    @BindView(R2.id.tv_all_price)
    TextView tvAllPrice;
    @BindView(R2.id.iv_shop_name)
    ImageView ivShopName;
    @BindView(R2.id.tv_shop_name)
    TextView tvShopName;
    @BindView(R2.id.rv_wait_send_goods)
    RecyclerView rvWaitSendGoods;
    @BindView(R2.id.tv_order_number)
    TextView tvOrderNumber;
    @BindView(R2.id.ll_no_add_address)
    LinearLayout llNoAddAddress;
    @BindView(R2.id.tv_day_month)
    TextView tvDayMonth;
    @BindView(R2.id.tv_transaction_remind)
    TextView tvTransactionRemind;
    @BindView(R2.id.tv_transaction_number)
    TextView tvTransactionNumber;
    @BindView(R2.id.ll_pay_price_number)
    LinearLayout llPayPriceNumber;
    @BindView(R2.id.tv_point_count)
    TextView tvPointCount;
    @BindView(R2.id.tv_point_count_layout)
    LinearLayout tvPointCountLayout;
    @BindView(R2.id.tv_online_service)
    TextView tvOnlineService;
    @BindView(R2.id.ll_online_service)
    LinearLayout llOnlineService;
    @BindView(R2.id.tv_tel_service)
    TextView tvTelService;
    @BindView(R2.id.ll_tel_service)
    LinearLayout llTelService;
    @BindView(R2.id.countdownView_timing)
    CountdownView countdownViewTiming;
    @BindView(R2.id.tv_more_long_time)
    TextView tvMoreLongTime;
    @BindView(R2.id.tv_order_logistics)
    TextView tvOrderLogistics;
    @BindView(R2.id.tv_to_logistics)
    TextView tvToLogistics;
    @BindView(R2.id.tv_to_cancel)
    TextView tvToCancel;
    @BindView(R2.id.wd_bot_ll)
    LinearLayout wdBotLl;
    @BindView(R2.id.order_detail_layout)
    NestedScrollView orderDetailLayout;

    @BindView(R2.id.card_order_shop_name_tv)
    TextView cardOrderShopNameTv;
    @BindView(R2.id.tv_cardbag_order_title)
    TextView tv_cardbag_order_title;
    @BindView(R2.id.tv_cardbag_order_discount_price)
    TextView tv_cardbag_order_discount_price;
    @BindView(R2.id.tv_cardbag_order_price)
    TextView tv_cardbag_order_price;
    @BindView(R2.id.card_goods_num_tv)
    TextView card_goods_num_tv;
    @BindView(R2.id.card_goods_sku_name)
    TextView card_goods_sku_name;
    @BindView(R2.id.iv_cardbag_order_card)
    ImageView ivCardbagOrderCard;
    @BindView(R2.id.card_order_detail_layout)
    LinearLayout card_order_detail_layout;
    @BindView(R2.id.order_detail_address_layout)
    LinearLayout order_detail_address_layout;
    @BindView(R2.id.order_detail_shop_layout)
    RelativeLayout order_detail_shop_layout;
    @BindView(R2.id.order_detail_sendType_layout)
    LinearLayout order_detail_sendType_layout;
    @BindView(R2.id.card_order_detail_line_layout)
    LinearLayout card_order_detail_line_layout;
    @BindView(R2.id.order_detail_sendType_line)
    View order_detail_sendType_line;
    @BindView(R2.id.order_detail_goods_line)
    View order_detail_goods_line;
    @BindView(R2.id.tv_cardbag_order_phone)
    TextView tv_cardbag_order_phone;
    @BindView(R2.id.tv_cardbag_order_change)
    TextView tv_cardbag_order_change;
    @BindView(R2.id.card_sms_tv)
    TextView card_sms_tv;
    @BindView(R2.id.order_reasons_tv)
    TextView orderReasonsTv;
    @BindView(R2.id.order_reasons_layout)
    LinearLayout orderReasonsLayout;
    @BindView(R2.id.order_leaving_layout)
    LinearLayout orderLeavingLayout;
    @BindView(R2.id.order_leaving_tv)
    TextView orderLeavingTv;
    @BindView(R2.id.order_detail_refresh)
    SmartRefreshLayout orderDetailRefresh;
    @BindView(R2.id.orderdetail_tax_layout)
    LinearLayout orderDetailTaxLayout;
    @BindView(R2.id.orderdetail_tax_price_tv)
    TextView orderDetailTaxPriceTv;
    @BindView(R2.id.orderDetail_shop_coupon_layout)
    LinearLayout orderDetailShopCouponLayout;
    @BindView(R2.id.orderDetail_shop_coupon_tv)
    TextView orderDetailShopCouponTv;
    @BindView(R2.id.refund_cancel_order_tv)
    TextView refundCancelOrderTv;

    private String orderId;
    private int couponMark;
    private OrderDetailAdapter orderDetailAdapter;
    private NewCommPayPopUp payPopUp;
    private OrderDetailBean mOrderDetailBean;
    private RejectOrderPopUp rejectOrderPopUp;
    private String orderRejectText;
    private CancelCouponOrderPop cancelCouponOrderPop;
    private ReasonDialog dialog;
    private Disposable intervalInterval;
    private boolean isRefreshCardTime = false;

    @Override
    protected BaseMvpPresenter createPresenter() {
        return null;
    }

    @Override
    protected int getContentView() {
        return R.layout.module_shopping_activity_waitting_deliver_goods;
    }

    @Override
    protected void initView() {
        setImmersionBar(commitOrderToolbar);
        tvTitle.setText("订单详情");
        rvWaitSendGoods.setLayoutManager(new LinearLayoutManager(this));
        orderDetailAdapter = new OrderDetailAdapter(R.layout.module_shopping_item_commit_order_item, new ArrayList<>());
        rvWaitSendGoods.setAdapter(orderDetailAdapter);
        orderDetailAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                RouterCommonUtils.startParameterActivity(RouterIntentConstant.MODULE_SHOPPING_GOODS_DETAIL, "url", Constant.GOODS_DETAIL_URL + orderDetailAdapter.getData().get(position).getGoodsId());
                finish();
            }
        });
    }

    @Override
    protected void addListener() {
        tvBack.setOnClickListener(v -> finish());
        llOnlineService.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(OrderDetailActivity.this, BaseX5WebActivity.class)
                        .putExtra("url", Constant.CUSTOM_SERVICE_URL)
                        .putExtra("title", "在线客服"));
            }
        });
        llTelService.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent5 = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + 9521133));
                startActivity(intent5);
            }
        });
    }

    @Override
    protected void initDatas() {
        orderId = getIntent().getStringExtra("orderId");
        couponMark = getIntent().getIntExtra("couponMark", 0);
        if (!Preconditions.isNullOrEmpty(orderId)) {
            getOrderDetailData();
        }
    }

    /**
     * 获取订单详情
     */
    private void getOrderDetailData() {
        new OrderDetailTask(OrderDetailActivity.this, new ITaskCallbackListener() {
            @Override
            public void doTaskComplete(Object o) {
                OrderDetailBean orderDetailBean = (OrderDetailBean) o;
                if (!Preconditions.isNullOrEmpty(orderDetailBean)) {

                    setDatas(orderDetailBean);
                }
            }
        }).execute(orderId);
    }

    /**
     * @param orderDetailBean
     */
    private void setDatas(OrderDetailBean orderDetailBean) {
        mOrderDetailBean = orderDetailBean;
        orderDetailRefresh.setOnRefreshListener(this::onRefresh);
        if (!Preconditions.isNullOrEmpty(orderDetailBean) && !Preconditions.isNullOrEmpty(orderDetailBean.getOrderItemList())) {
            orderDetailRefresh.finishRefresh();
            loadOrderDetailInfo();
        }
    }

    private void loadOrderDetailInfo() {
        handleOrderFromDetail(mOrderDetailBean);
    }

    /**
     * 不同订单来源详情状态处理
     *
     * @param orderDetailBean
     */
    private void handleOrderFromDetail(OrderDetailBean orderDetailBean) {
        showOrderFromInfo(orderDetailBean);
        showPayType(orderDetailBean);
        showGoodsPrice(orderDetailBean);
        showPaymentCode(orderDetailBean);
        showOrderReasons();
        showOrderLeaving();
        showOrderTaxFee();
        showPayIntegral();
        handlerOrderStatus(orderDetailBean);
        handlerRefundMarkOrderStatus(orderDetailBean);
    }

    /**
     * 不同订单来源UI展示
     *
     * @param orderDetailBean
     */
    private void showOrderFromInfo(OrderDetailBean orderDetailBean) {
        if (isOrderDetailFromType(mOrderDetailBean.getOrderItemList().get(0))) {
            SHelper.vis(orderDetailLayout, card_order_detail_layout, card_order_detail_line_layout, tvSendPrice, tvCouponPrice);
            SHelper.gone(order_detail_address_layout, rvWaitSendGoods, order_detail_shop_layout, order_detail_sendType_layout, order_detail_goods_line);
            showCardOrderDetailGoodsInfo(orderDetailBean, orderDetailBean.getOrderItemList().get(0));
            intervalRefreshCardPayState();
        } else {
            SHelper.vis(orderDetailLayout);
            orderDetailAdapter.setNewData(orderDetailBean.getOrderItemList());
            showSendType(orderDetailBean);
            showSendPrice(orderDetailBean);
            showShopInfo(orderDetailBean);
            showShopCouponInfo(orderDetailBean);
            showOrderAddressText(orderDetailBean);
        }
    }

    /**
     * 显示拒单原因
     */
    private void showOrderReasons() {
        if (!Preconditions.isNullOrEmpty(mOrderDetailBean.getReasons())) {
            SHelper.vis(orderReasonsLayout);
            orderReasonsTv.setText(mOrderDetailBean.getReasons());
        }
    }

    /**
     * 显示留言原因
     */
    private void showOrderLeaving() {
        if (!Preconditions.isNullOrEmpty(mOrderDetailBean.getUserInfo())) {
            SHelper.vis(orderLeavingLayout);
            orderLeavingTv.setText(mOrderDetailBean.getUserInfo());
        }
    }

    /**
     * 显示税费
     */
    private void showOrderTaxFee() {
        if (mOrderDetailBean.getTaxFee() > 0) {
            SHelper.vis(orderDetailTaxLayout, tvRedPackageLine);
            orderDetailTaxPriceTv.setText(AppConstants.MONEY + mOrderDetailBean.getTaxFee());
        }
    }

    /**
     * 卡包支付来源商品
     */
    private void showCardOrderDetailGoodsInfo(OrderDetailBean orderDetailBean, OrderDetailBean.OrderItemListBean orderItemListBean) {
        cardOrderShopNameTv.setText(orderDetailBean.getShopName());
        BaseImageLoaderUtils.getInstance().loadDefaltImage(this, ivCardbagOrderCard, orderItemListBean.getGoodsImg());
        tv_cardbag_order_title.setText(orderItemListBean.getGoodsName());
        tv_cardbag_order_discount_price.setText(orderItemListBean.getPrice() + "");
        card_goods_num_tv.setText("x" + orderItemListBean.getGoodsCount());
        card_goods_sku_name.setText(orderItemListBean.getSkuName());
        tv_cardbag_order_phone.setText(orderDetailBean.getAddressPhone());
        tvOrderNumber.setText(orderDetailBean.getOrderId());
        tvDayMonth.setText(orderDetailBean.getCreateDate());
        tvCouponPrice.setText(AppConstants.MONEY + orderDetailBean.getPlatformPrice());
        SHelper.gone(tv_cardbag_order_change);
    }

    /**
     * 不同来源
     *
     * @param orderItemListBean
     * @return
     */
    private boolean isOrderDetailFromType(OrderDetailBean.OrderItemListBean orderItemListBean) {
        int cardPayType = orderItemListBean.getType();
        if (cardPayType == 1 || cardPayType == 2) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 显示自提方式
     *
     * @param orderDetailBean
     */
    private void showSendType(OrderDetailBean orderDetailBean) {
        if ("1".equals(orderDetailBean.getSendType())) {
            tvDeliveryMethod.setText("快递");
        } else if ("2".equals(orderDetailBean.getSendType())) {
            tvDeliveryMethod.setText("自提");
        }
    }

    /**
     * 显示支付方式
     *
     * @param orderDetailBean
     */
    private void showPayType(OrderDetailBean orderDetailBean) {
        if ("Alipay".equals(orderDetailBean.getPayType())) {
            tvPayType.setText("支付宝");
        } else if ("MicroMessenger".equals(orderDetailBean.getPayType())) {
            tvPayType.setText("微信");
        } else if ("CardBagPay".equals(orderDetailBean.getPayType())) {
            tvPayType.setText("卡包");
        } else if ("integralPay".equals(orderDetailBean.getPayType())) {
            tvPayType.setText("积分");
        } else {
            tvPayType.setText("待支付");
        }
    }

    /**
     * 显示配送价格
     *
     * @param orderDetailBean
     */
    private void showSendPrice(OrderDetailBean orderDetailBean) {
        SHelper.vis(tvSendPrice);
        if (!Preconditions.isNullOrEmpty(orderDetailBean.getSendPrice())) {
            tvSendPrice.setText("¥" + orderDetailBean.getSendPrice());
        } else {
            tvSendPrice.setText("¥ 0.00");
        }
    }

    /**
     * 显示支付获的积分
     */
    private void showPayIntegral() {
        SHelper.vis(tvPointCountLayout);
        double integralNum = ConverterUtils.toDouble(mOrderDetailBean.getRealPrice());
        tvPointCount.setText(CharacterUtils.roundByScale(Math.floor(integralNum / 10 * 1)));
    }

    /**
     * 显示店铺信息
     *
     * @param orderDetailBean
     */
    private void showShopInfo(OrderDetailBean orderDetailBean) {

        //商品名称
        if (!Preconditions.isNullOrEmpty(orderDetailBean.getShopName())) {
            SHelper.vis(ivShopName, tvShopName);
            tvShopName.setText(orderDetailBean.getShopName());
        } else {
            SHelper.gone(ivShopName, tvShopName);
        }
    }

    /**
     * 店铺优惠卷
     *
     * @param orderDetailBean
     */
    private void showShopCouponInfo(OrderDetailBean orderDetailBean) {
        if (!Preconditions.isNullOrEmpty(orderDetailBean.getCouponPrice()) && ConverterUtils.toDouble(orderDetailBean.getCouponPrice()) > 0) {
            SHelper.vis(orderDetailShopCouponTv, orderDetailShopCouponLayout);
            orderDetailShopCouponTv.setText("-" + orderDetailBean.getCouponPrice());
        } else {
            SHelper.gone(orderDetailShopCouponTv, orderDetailShopCouponLayout);
        }
    }

    /**
     * 显示订单基本信息
     *
     * @param orderDetailBean
     */
    private void showOrderAddressText(OrderDetailBean orderDetailBean) {
        SHelper.vis(llAddAddress, viewLineTwo, viewLineOne, tvCouponPrice);
        SHelper.gone(ivArrowToAddressList);
        tvConsigneeName.setText(orderDetailBean.getAddressName());
        tvConsigneePhone.setText(orderDetailBean.getAddressPhone());
        showConsigneeAddress(orderDetailBean);
        ivAddressType.setBackgroundResource(R.mipmap.head_item_ziti);
        tvCouponPrice.setText(AppConstants.MONEY + orderDetailBean.getPlatformPrice());
        tvOrderNumber.setText(orderDetailBean.getOrderId());
        tvDayMonth.setText(orderDetailBean.getCreateDate());
    }

    /**
     * 显示收货地址
     *
     * @param orderDetailBean
     */
    private void showConsigneeAddress(OrderDetailBean orderDetailBean) {
        if ("2".equals(orderDetailBean.getSendType())) {
            if (!Preconditions.isNullOrEmpty(orderDetailBean.getMentionPhone()) && !Preconditions.isNullOrEmpty(orderDetailBean.getMentionPhone())) {
                tvConsigneeAddress.setText(orderDetailBean.getAddress() + "（" + orderDetailBean.getMentionName() + "）" + "（" + orderDetailBean.getMentionPhone() + "）");
            } else {
                tvConsigneeAddress.setText(orderDetailBean.getAddress());
            }
        } else {
            tvConsigneeAddress.setText(orderDetailBean.getAddress());
        }
    }


    /**
     * 显示支付交易号
     *
     * @param orderDetailBean
     */
    private void showPaymentCode(OrderDetailBean orderDetailBean) {
        //支付交易号
        if (!Preconditions.isNullOrEmpty(orderDetailBean.getPaymentCode())) {
            SHelper.vis(llPayPriceNumber);
            tvTransactionNumber.setText(orderDetailBean.getPaymentCode());
        } else {
            SHelper.gone(llPayPriceNumber);
        }
    }

    /**
     * 显示商品价格
     *
     * @param orderDetailBean
     */
    private void showGoodsPrice(OrderDetailBean orderDetailBean) {
        if (!Preconditions.isNullOrEmpty(orderDetailBean.getTotalRealPrice())) {
            tvGoodsPrice.setText(AppConstants.MONEY + orderDetailBean.getTotalRealPrice());
        } else {
            tvGoodsPrice.setText(AppConstants.MONEY + orderDetailBean.getTotalPrice());
        }
        tvAllPrice.setText(AppConstants.MONEY + orderDetailBean.getRealPrice());
    }

    /**
     * 未支付订单倒计时
     */
    private void orderTaktTime() {
        if (ConverterUtils.toInt(mOrderDetailBean.getTaktTime()) != 0) {
            SHelper.vis(countdownViewTiming);
            countdownViewTiming.start(ConverterUtils.toLong(mOrderDetailBean.getTaktTime()));
            countdownViewTiming.setOnCountdownEndListener(new CountdownView.OnCountdownEndListener() {
                @Override
                public void onEnd(CountdownView cv) {
                    getOrderDetailData();
                    handleRxEventPost(false);
                }
            });
        } else {
            SHelper.gone(countdownViewTiming);
        }
    }

    /**
     * 预售商品显示发货时间
     */
    private void saleTaktTime() {
        if (!Preconditions.isNullOrEmpty(mOrderDetailBean.getSaleStartTime())) {
            if (mOrderDetailBean.getBuyType() == 1) {
                SHelper.vis(tvMoreLongTime);
                tvMoreLongTime.setText("预计" + mOrderDetailBean.getSaleStartTime() + "发货");
            }
        } else {
            SHelper.gone(tvMoreLongTime);
        }
    }

    /**
     * 根据不同订单状态展示icon
     *
     * @param orderResource
     */
    private void setOrderStateIv(int orderResource) {
        ivOrderState.setBackgroundResource(orderResource);
    }

    /**
     * 设置短信提示语
     *
     * @param smsMsg
     */
    private void setPayCardSmsText(String smsMsg, boolean payOrderFail) {
        card_sms_tv.setText(smsMsg);
        if (payOrderFail) {
            SHelper.gone(tv_cardbag_order_phone);
        }
    }

    /**
     * 处理卡包订单来源支付成功短信提示语
     */
    private void handlePayCardSuccessState(String smsMsg, boolean payOrderFail) {
        if (isOrderDetailFromType(mOrderDetailBean.getOrderItemList().get(0))) {
            setPayCardSmsText(smsMsg, payOrderFail);
            SHelper.gone(tvOrderLogistics);
        } else {
            setTvOrderLogisticsTitle(R.string.order_logistics);
            SHelper.vis(tvOrderLogistics);
        }
        dispose();
    }

    /**
     * 用户取消申请/分享赚退款订单
     *
     * @param orderDetailBean
     */
    private void handlerRefundMarkOrderStatus(OrderDetailBean orderDetailBean) {
        String refundMark = orderDetailBean.getRefundMark();
        if (orderDetailBean.getOrderItemType() == OrderRefundMarkType.ORDER_TYPE_1) {
            if (refundMark.equals(OrderRefundMarkType.ORDER_REFUND_STATUS_1.getOrderRefundStatus())) {
                refundCancelOrderTv.setText(" 取消中 ");
                refundCancelOrderTv.setEnabled(false);
                SHelper.vis(refundCancelOrderTv);
            } else if (refundMark.equals(OrderRefundMarkType.ORDER_REFUND_STATUS_2.getOrderRefundStatus())) {
                refundCancelOrderTv.setText("取消成功");
                refundCancelOrderTv.setEnabled(false);
                SHelper.vis(refundCancelOrderTv);
            } else if (refundMark.equals(OrderRefundMarkType.ORDER_REFUND_STATUS_3.getOrderRefundStatus())) {
                refundCancelOrderTv.setText("取消被拒");
                refundCancelOrderTv.setEnabled(true);
                SHelper.vis(refundCancelOrderTv);

            }
        }
    }

    /**
     * 处理订单状态
     *
     * @param orderDetailBean
     */
    private void handlerOrderStatus(OrderDetailBean orderDetailBean) {
        String orderStatus = orderDetailBean.getStatus();
        //待支付
        if (orderStatus.equals(OrderStatusType.ORDER_UNPAID_PAY_STATUS.getOrderStatus())) {
            isRefreshCardTime = false;
            SHelper.vis(tvToLogistics, tvToCancel, tvOrderLogistics, countdownViewTiming);
            setPayCardSmsText(getString(R.string.order_card_pay_sms_phone), false);
            setTvToCancelTitle(R.string.immediately_pay);
            setTvToLogisticsTitle(R.string.cancel_order);
            SHelper.gone(tvOrderLogistics);
            setOrderStateIv(R.mipmap.ic_wait_payfor);
            addOrderListener(tvToLogistics, tvToCancel, tvOrderLogistics, OrderStatusType.ORDER_UNPAID_PAY_STATUS.getOrderStatus(), orderDetailBean);
            orderTaktTime();
            //已支付 未接单
        } else if (orderStatus.equals(OrderStatusType.ORDER_ALREADY_PAY_STATUS.getOrderStatus())) {
            isRefreshCardTime = true;
            setTvToLogisticsTitle(R.string.cancel_order);
            setTvOrderLogisticsTitle(R.string.order_logistics);
            SHelper.vis(tvToLogistics, tvOrderLogistics);
            SHelper.gone(tvToCancel);
            setOrderStateIv(R.mipmap.ic_wait_dispose);
            addOrderListener(tvToLogistics, tvToCancel, tvOrderLogistics, OrderStatusType.ORDER_ALREADY_PAY_STATUS.getOrderStatus(), orderDetailBean);
            //已接单,待发货
        } else if (orderStatus.equals(OrderStatusType.ORDER_RECEIPT_STATUS.getOrderStatus())) {
            isRefreshCardTime = true;
            setTvToCancelTitle(R.string.reminding_shipments);
            setTvOrderLogisticsTitle(R.string.order_logistics);
            setTvRefundCancelOrderTitle(R.string.cancel_order);
            SHelper.gone(tvToLogistics);
            SHelper.vis(tvOrderLogistics, tvToCancel, refundCancelOrderTv);
            setOrderStateIv(R.mipmap.ic_wait_send_goods);
            addOrderListener(tvToLogistics, tvToCancel, tvOrderLogistics, OrderStatusType.ORDER_RECEIPT_STATUS.getOrderStatus(), orderDetailBean);
            //待收货
        } else if (orderStatus.equals(OrderStatusType.ORDER_SHIPPED_STATUS.getOrderStatus())) {
            setTvOrderLogisticsTitle(R.string.order_logistics);
            if (couponMark == 0) {
                setTvToCancelTitle(R.string.confirm_the_goods);
            } else {
                setTvToCancelTitle(R.string.confirm_the_goods_coupon);
            }
            SHelper.vis(tvToCancel, tvOrderLogistics);
            SHelper.gone(tvToLogistics);
            setOrderStateIv(R.mipmap.ic_wait_goods_receipt);
            addOrderListener(tvToLogistics, tvToCancel, tvOrderLogistics, OrderStatusType.ORDER_SHIPPED_STATUS.getOrderStatus(), orderDetailBean);
            //已提醒发货
        } else if (orderStatus.equals(OrderStatusType.ORDER_DELIVERY_STATUS.getOrderStatus())) {
            isRefreshCardTime = true;
            setTvOrderLogisticsTitle(R.string.order_logistics);
            setTvToCancelTitle(R.string.reminding_the_shipments);
            setTvRefundCancelOrderTitle(R.string.cancel_order);
            setTvWidthParams(tvToCancel);
            SHelper.gone(tvToLogistics);
            SHelper.vis(tvToCancel, tvOrderLogistics, refundCancelOrderTv);
            setOrderStateIv(R.mipmap.ic_wait_send_goods);
            addOrderListener(tvToLogistics, tvToCancel, tvOrderLogistics, OrderStatusType.ORDER_DELIVERY_STATUS.getOrderStatus(), orderDetailBean);
            //交易成功(已收货,待评价)
        } else if (orderStatus.equals(OrderStatusType.ORDER_SUCCESS_STATUS.getOrderStatus())) {
            isRefreshCardTime = false;
            handlePayCardSuccessState(getString(R.string.order_card_sms_phone), false);
            SHelper.vis(tvToCancel);
            SHelper.gone(tvOrderLogistics, tvToLogistics);
            setTvToCancelTitle(R.string.order_commint);
            setOrderStateIv(R.mipmap.ic_wait_evaluate);
            addOrderListener(tvToLogistics, tvToCancel, tvOrderLogistics, OrderStatusType.ORDER_SUCCESS_STATUS.getOrderStatus(), orderDetailBean);
            //交易成功(已评价)
        } else if (orderStatus.equals(OrderStatusType.ORDER_SUCCESS_EVALUATED_STATUS.getOrderStatus())) {
            isRefreshCardTime = false;
            setTvOrderLogisticsTitle(R.string.order_logistics);
            setTvToCancelTitle(R.string.delete_order);
            SHelper.vis(tvOrderLogistics, tvToCancel);
            setOrderStateIv(R.mipmap.ic_wait_order_over);
            addOrderListener(tvToLogistics, tvToCancel, tvOrderLogistics, OrderStatusType.ORDER_SUCCESS_EVALUATED_STATUS.getOrderStatus(), orderDetailBean);
            //商家取消 | 用户取消 | 长时间未支付 | 自动取消
        } else if (orderStatus.equals(OrderStatusType.ORDER_USER_CLOSE_STATUS.getOrderStatus()) ||
                orderStatus.equals(OrderStatusType.ORDER_MERCHANT_CLOSE_STATUS.getOrderStatus()) ||
                orderStatus.equals(OrderStatusType.ORDER_SYSTEM_CLOSE_STATUS.getOrderStatus()) ||
                orderStatus.equals(OrderStatusType.ORDER_MERCHANT_REFUSAL_CLOSE_STATUS.getOrderStatus())) {
            handlePayCardSuccessState(getString(R.string.order_card_fail_name), true);
            isRefreshCardTime = false;
            setTvToCancelTitle(R.string.delete_order);
            SHelper.gone(tvToLogistics);
            SHelper.vis(tvToCancel);
            setOrderStateIv(R.mipmap.ic_wait_cancel_byself);
            addOrderListener(tvToLogistics, tvToCancel, tvOrderLogistics, orderStatus, orderDetailBean);
        }
    }

    private void setTvToLogisticsTitle(int showTitle) {
        tvToLogistics.setText(showTitle);
    }

    private void setTvToCancelTitle(int showRedBtn) {
        tvToCancel.setText(showRedBtn);
    }

    private void setTvOrderLogisticsTitle(int showGrayBtn) {
        tvOrderLogistics.setText(showGrayBtn);
    }

    private void setTvRefundCancelOrderTitle(int showRefundTitle) {
        refundCancelOrderTv.setText(showRefundTitle);
    }

    /**
     * 支付弹窗
     */
    private void showPayPop(View v) {
        payPopUp = new NewCommPayPopUp(this, mOrderDetailBean.getRealPrice(), OrderPayFormType.PAY_FORM_TYPE_1.getPayFormType());
        payPopUp.setConfirmPayOrder(new SubmitOrderResultBean(orderId));
        payPopUp.showAtLocation(v, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
    }

    /**
     * 订单状态按钮监听
     */
    private void addOrderListener(TextView tvToLogistics, TextView tvToCancel, TextView tvOrderLogistics, String orderStatus, OrderDetailBean orderDetailBean) {

        tvToLogistics.setOnClickListener(v -> {
            // 未支付 取消订单
            if (orderStatus.equals(OrderStatusType.ORDER_UNPAID_PAY_STATUS.getOrderStatus())) {
                showCancelDialog(orderId, OrderStatusType.FUNMARK_1, OrderStatusType.ORDER_UNPAID_PAY_STATUS.getOrderStatus(), true);
                // 已支付 未接单 取消订单
            } else if (orderStatus.equals(OrderStatusType.ORDER_ALREADY_PAY_STATUS.getOrderStatus())) {
                showCancelDialog(orderId, OrderStatusType.FUNMARK_1, OrderStatusType.ORDER_UNPAID_PAY_STATUS.getOrderStatus(), true);
                // 已接单,待发货 取消订单
            } else if (orderStatus.equals(OrderStatusType.ORDER_RECEIPT_STATUS.getOrderStatus())) {
                showCancelDialog(orderId, OrderStatusType.FUNMARK_1, OrderStatusType.ORDER_UNPAID_PAY_STATUS.getOrderStatus(), true);
                // 已提醒商家发货 取消订单
            } else if (orderStatus.equals(OrderStatusType.ORDER_DELIVERY_STATUS.getOrderStatus())) {
                showCancelDialog(orderId, OrderStatusType.FUNMARK_1, OrderStatusType.ORDER_UNPAID_PAY_STATUS.getOrderStatus(), true);
            }
        });

        //用户取消申请/分享赚退款订单标识
        refundCancelOrderTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (!Preconditions.isNullOrEmpty(orderDetailBean.getRefundMark())) {
                    if (orderDetailBean.getRefundMark().equals(OrderRefundMarkType.ORDER_REFUND_STATUS_3.getOrderRefundStatus())) {
                        if (dialog == null) {
                            dialog = new ReasonDialog(OrderDetailActivity.this);
                        }
                        dialog.setReason(orderDetailBean.getMchReasons());
                        dialog.show();
                        return;
                    }
                }

                //代发货
                if (orderStatus.equals(OrderStatusType.ORDER_RECEIPT_STATUS.getOrderStatus())) {
                    showCancelDialog(orderId, OrderStatusType.FUNMARK_1, OrderStatusType.ORDER_UNPAID_PAY_STATUS.getOrderStatus(), false);
                    return;
                }

                //提醒商家代发货
                if (orderStatus.equals(OrderStatusType.ORDER_DELIVERY_STATUS.getOrderStatus())) {
                    showCancelDialog(orderId, OrderStatusType.FUNMARK_1, OrderStatusType.ORDER_UNPAID_PAY_STATUS.getOrderStatus(), false);
                    return;
                }
            }
        });

        tvToCancel.setOnClickListener(v -> {
            //立即支付
            if (orderStatus.equals(OrderStatusType.ORDER_UNPAID_PAY_STATUS.getOrderStatus())) {
                showPayPop(v);
                //确认发货
            } else if (orderStatus.equals(OrderStatusType.ORDER_SHIPPED_STATUS.getOrderStatus())) {
                if (couponMark == 0) {
                    confirmOrderDialog(orderId, OrderStatusType.FUNMARK_5, OrderStatusType.ORDER_SHIPPED_STATUS.getOrderStatus());
                } else {
                    confirmOrderCouponDialog(orderId, OrderStatusType.FUNMARK_5, OrderStatusType.ORDER_SHIPPED_STATUS.getOrderStatus());
                }
                //交易完成评价
            } else if (orderStatus.equals(OrderStatusType.ORDER_SUCCESS_STATUS.getOrderStatus())) {
                startActivity(new Intent(OrderDetailActivity.this, OrderEvaluateActivity.class)
                        .putExtra("orderId", orderId)
                        .putExtra("shopId", orderDetailBean.getShopId()));
                finish();
                //删除订单
            } else if (orderStatus.equals(OrderStatusType.ORDER_SUCCESS_EVALUATED_STATUS.getOrderStatus())) {
                showDeleteDialog();
                //删除订单
            } else if (orderStatus.equals(OrderStatusType.ORDER_USER_CLOSE_STATUS.getOrderStatus()) ||
                    orderStatus.equals(OrderStatusType.ORDER_MERCHANT_CLOSE_STATUS.getOrderStatus()) ||
                    orderStatus.equals(OrderStatusType.ORDER_SYSTEM_CLOSE_STATUS.getOrderStatus()) ||
                    orderStatus.equals(OrderStatusType.ORDER_MERCHANT_REFUSAL_CLOSE_STATUS.getOrderStatus())) {
                showDeleteDialog();
                //提醒发货
            } else if (orderStatus.equals(OrderStatusType.ORDER_RECEIPT_STATUS.getOrderStatus())) {
                updateOrderStatus(orderId, OrderStatusType.FUNMARK_4, OrderStatusType.ORDER_RECEIPT_STATUS.getOrderStatus());
            }
        });

        tvOrderLogistics.setOnClickListener(v -> {
            Intent intent = new Intent(OrderDetailActivity.this, OrderTrackActivity.class);
            intent.putExtra("orderId", orderId);
            intent.putExtra("address", orderDetailBean.getAddress());
            intent.putExtra("sendType", orderDetailBean.getSendType());
            intent.putExtra("phone", orderDetailBean.getAddressPhone());
            intent.putExtra("mentionPhone", orderDetailBean.getMentionPhone());
            intent.putExtra("expressName", orderDetailBean.getExpressName());
            intent.putExtra("expressCode", orderDetailBean.getExpressNumber());
            startActivity(intent);
        });
    }

    /**
     * 更新订单状态
     *
     * @param orderId
     * @param funMark
     */
    private void updateOrderStatus(String orderId, String funMark, String orderStatus) {
        new ConfirmOrderStatusTask(this, o -> {
            BaseResponseInfo baseResponseInfo = (BaseResponseInfo) o;

            if (Preconditions.isNullOrEmpty(baseResponseInfo)) {
                return;
            }
            if (baseResponseInfo.getCode() == ConstantErrorCode.SUCC_CODE) {
                handleUpdateOrderStatus(orderStatus);
                if (couponMark != 0) {
                    //获取优惠券
                    getCoupon(orderId);
                }
            } else {
                WpToast.l(OrderDetailActivity.this, baseResponseInfo.getMessage());
            }
        }).execute(orderId, funMark, orderRejectText);
    }

    /**
     * 代发货 取消订单审核状态
     *
     * @param orderId
     */
    private void cancelReturnOrderStatus(String orderId) {
        new ConfirmCancelOrderStatusTask(this, o -> {
            BaseResponseInfo baseResponseInfo = (BaseResponseInfo) o;

            if (Preconditions.isNullOrEmpty(baseResponseInfo)) {
                return;
            }

            if (baseResponseInfo.getCode() == ConstantErrorCode.SUCC_CODE) {
                refundCancelOrderTv.setText(" 取消中 ");
                refundCancelOrderTv.setEnabled(false);
            } else {
                WpToast.l(OrderDetailActivity.this, baseResponseInfo.getMessage());
            }
        }).execute(orderId, orderRejectText);
    }


    private void getCoupon(String orderId) {
        new SpecialCouponForOrderTask(this, o -> {
            SpecialCouponBean specialCouponBean = (SpecialCouponBean) o;
            if (Preconditions.isNullOrEmpty(specialCouponBean) || Preconditions.isNullOrEmpty(specialCouponBean.get_embedded()) || Preconditions.isNullOrEmpty(specialCouponBean.get_embedded().getContent())) {
                new NotSnatchDialog(OrderDetailActivity.this).show();
                return;
            }
            SpecialCouponDialog dialog = new SpecialCouponDialog(OrderDetailActivity.this);
            dialog.setData(specialCouponBean);
            dialog.show();
        }).execute(orderId);
    }


    /**
     * 更新订单状态
     *
     * @param orderStatus
     */
    private void handleUpdateOrderStatus(String orderStatus) {
        if (orderStatus.equals(OrderStatusType.ORDER_RECEIPT_STATUS.getOrderStatus())) {
            WpToast.l(this, "提醒发货成功");
            setTvWidthParams(tvToCancel);
            setTvOrderLogisticsTitle(R.string.order_logistics);
            setTvToCancelTitle(R.string.reminding_the_shipments);
            tvToCancel.setEnabled(false);
            handleRxEventPost(false);
        } else if (orderStatus.equals(OrderStatusType.ORDER_SHIPPED_STATUS.getOrderStatus())) {
            WpToast.l(this, "确认收货成功");
            getOrderDetailData();
            handleRxEventPost(false);
        } else if (orderStatus.equals(OrderStatusType.ORDER_UNPAID_PAY_STATUS.getOrderStatus())) {
            WpToast.l(this, "取消成功");
            handleRxEventPost(true);
        }
    }

    /**
     * 发送消息更新列表
     */
    private void handleRxEventPost(boolean isFinish) {
        OrderEvent orderEvent = new OrderEvent();
        orderEvent.setOrderType(OrderEvent.ORDER_TYPE_1);
        RxBus.getInstance().post(orderEvent);
        if (isFinish) {
            finish();
        }
    }

    /**
     * 确认收货弹框
     *
     * @param orderId
     * @param funMark
     * @param orderStatus
     */
    private void confirmOrderDialog(String orderId, String funMark, String orderStatus) {
        new DialogUtils(this, "确认收货前，请确保你已经收到商品！").setOnDialogClickListener(new DialogUtils.OnDialogClickListener() {
            @Override
            public void onLeftClick() {
            }

            @Override
            public void onRightClick() {
                updateOrderStatus(orderId, funMark, orderStatus);
            }
        });
    }

    private void confirmOrderCouponDialog(String orderId, String funMark, String orderStatus) {
        new ReceivingGoodsDialog(this, () -> updateOrderStatus(orderId, funMark, orderStatus)).show();
    }

    /**
     * 删除订单弹框
     */
    private void showDeleteDialog() {
        AlertDialog alertDialog = new AlertDialog.Builder(OrderDetailActivity.this)
                .setTitle(R.string.delete)
                .setMessage(R.string.is_sure_delete_order)
                .setPositiveButton(R.string.delete, (dialog, which) -> {
                    if (!Preconditions.isNullOrEmpty(orderId)) {
                        handleDeleteOrder();
                    }
                })
                .setNegativeButton(R.string.cancel, null).show();
        alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).setTextColor(Color.RED);
        alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE).setTextColor(Color.BLACK);
    }

    /**
     * 删除订单
     */
    private void handleDeleteOrder() {
        new OrderDeleteTask(this, o -> {
            BaseResponseInfo baseResponseInfo = (BaseResponseInfo) o;
            if (baseResponseInfo.getCode() == ConstantErrorCode.SUCC_CODE) {
                WpToast.l(OrderDetailActivity.this, "删除成功");
                handleRxEventPost(true);
            } else {
                WpToast.l(OrderDetailActivity.this, "删除失败");
            }

        }).execute(orderId);
    }

    /**
     * 取消订单弹框
     *
     * @param orderId
     * @param funMark
     * @param orderStatus
     */
    private void showCancelDialog(String orderId, String funMark, String orderStatus, boolean isReturnOrderStatus) {
        AlertDialog alertDialog = new AlertDialog.Builder(OrderDetailActivity.this)
                .setTitle("取消")
                .setMessage("确定要取消订单吗？")
                .setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        if (!Preconditions.isNullOrEmpty(orderId)) {
                            if (ConverterUtils.toDouble(mOrderDetailBean.getPlatformPrice()) > 0) {
                                cancelCouponOrderPop = new CancelCouponOrderPop(OrderDetailActivity.this);
                                cancelCouponOrderPop.addOrderId(orderId);
                                cancelCouponOrderPop.setReceiveCouponListener(new CancelCouponOrderPop.ReceiveCouponListener() {
                                    @Override
                                    public void receiveCouponSuccess() {
                                        showRejectOrderPop(orderId, funMark, orderStatus, isReturnOrderStatus);
                                    }
                                });
                            } else {
                                showRejectOrderPop(orderId, funMark, orderStatus, isReturnOrderStatus);
                            }
                        }
                    }
                })
                .setNegativeButton(R.string.cancel, null).show();
        alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).setTextColor(Color.RED);
        alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE).setTextColor(Color.BLACK);
    }

    /**
     * 取消订单原因
     *
     * @param orderId
     * @param funMark
     * @param orderStatus
     */
    private void showRejectOrderPop(String orderId, String funMark, String orderStatus, boolean isReturnOrderStatus) {
        if (rejectOrderPopUp == null) {
            rejectOrderPopUp = new RejectOrderPopUp(this);
            rejectOrderPopUp.showRejectOrderPopUp(orderDetailLayout);
            rejectOrderPopUp.setRejectOrderListener(new RejectOrderPopUp.RejectOrderListener() {
                @Override
                public void getRejectOrderTv(String rejectText) {
                    orderRejectText = rejectText;
                    if (isReturnOrderStatus) {
                        updateOrderStatus(orderId, funMark, orderStatus);
                    } else {
                        cancelReturnOrderStatus(orderId);
                    }
                }
            });
        } else {
            rejectOrderPopUp.showRejectOrderPopUp(tvBack);
        }
    }

    /**
     * 设置显示文本宽度
     */
    private void setTvWidthParams(TextView tv) {
        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) tvToCancel.getLayoutParams();
        params.width = SHelper.dp2px(this, 100);
        tv.setLayoutParams(params);
    }

    @SuppressLint("CheckResult")
    public void intervalRefreshCardPayState() {
        if (isRefreshCardTime) {
            final long codeTimes = 5;
            intervalInterval = Flowable.interval(codeTimes, TimeUnit.SECONDS).observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new Consumer<Long>() {
                        @Override
                        public void accept(@NonNull Long aLong) throws Exception {
                            getOrderDetailData();
                        }
                    }, new Consumer<Throwable>() {
                        @Override
                        public void accept(Throwable throwable) throws Exception {
                            dispose();
                        }
                    });
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (!Preconditions.isNullOrEmpty(countdownViewTiming)) {
            countdownViewTiming.stop();
        }
        dispose();
    }

    private void dispose() {

        if (intervalInterval != null && !intervalInterval.isDisposed()) {
            intervalInterval.dispose();
        }
    }

    @Override
    public void onRefresh(RefreshLayout refreshLayout) {
        getOrderDetailData();
    }

}
